﻿package org.yoao.crm.tools;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;

public class FileAction {
	private static final Logger log = Logger.getLogger(FileAction.class);
	private File file = null;

	public void setFile(String filePath){
		this.file = new File(filePath);
	}

	public static String getFileName(){
		return new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date());
	}

	public boolean exists(){
		if(file == null) return false;
		return file.exists();
	}

	public boolean create(){
		try {
			if(!exists())
				file.createNewFile();
			else log.debug(file.getPath() + "已存在!");

			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	/***
	 * 创建目录
	 * @param filePath
	 * @return
	 */
	public boolean createFolder(){
		try {
			if(!exists())
				file.mkdir();
			else log.debug(file.getPath() + "已存在!");

			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
}